import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:flutter_wan_android/model/three_data.dart';
import 'package:flutter_wan_android/page/system_tx_detail.dart';
import 'package:flutter_wan_android/res/colors.dart';
import 'package:flutter_wan_android/res/theme.dart';
import 'package:flutter_wan_android/routes/route_util.dart';
import 'package:flutter_wan_android/widget/wan_appbar.dart';

class SystemTxList extends StatefulWidget {
  @override
  _SystemTxListState createState() => _SystemTxListState();
}

// 关于tabbar 的使用 https://www.jianshu.com/p/a2dac1451a93
class _SystemTxListState extends State<SystemTxList> {

  @override
  Widget build(BuildContext context) {

    var params = RouteUtil.getParams(context);

    ThreeData data = params["data"];
    var index = params["index"];

    var tabs = data.children.map<Widget>((e) =>  Text(e.name)).toList();
    var pages = data.children.map<Widget>((e) =>  SystemTxDetail(e.id)).toList();

    return Scaffold(
        appBar: WanAppbar(context, titleStr: data.name),
        body: DefaultTabController(
          length: data.children.length,
          initialIndex: index,
          child: Column(
            children: [
              Container(
                height: 40,
                width: double.infinity,
                color: wTheme.primary,
                child: TabBar(
                  labelColor: WColor.white,
                  unselectedLabelColor: WColor.white1,
                  labelStyle: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
                  unselectedLabelStyle: TextStyle(fontSize: 15),
                  isScrollable: true,
                  indicatorWeight: 0.1,
                  tabs: tabs,
                ),
              ),

              Expanded(
                flex: 1,
                child: TabBarView(children: pages),
              ),
            ],
          ),
        ));
  }
}
